package pzl.com.canvasapi.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * @author zl.peng
 * @version [1.0, 2016-11-21]
 */
public class V_Arcs extends View {
    Paint p;
    int w, h;

    public V_Arcs(Context context) {
        super(context);
    }

    public V_Arcs(Context context, AttributeSet attrs) {
        super(context, attrs);
        p = new Paint();
        p.setStrokeWidth(5);
        p.setAntiAlias(true);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        w = getWidth();
        h = getHeight();
    }

    public V_Arcs(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        p.setStyle(Paint.Style.FILL_AND_STROKE);
        p.setColor(Color.BLUE);
        RectF rectF = new RectF();
        rectF.left = 0;
        rectF.top = 15;
        rectF.right = w / 2;
        rectF.bottom = rectF.top + 200;

        canvas.drawArc(rectF, 0, 100, true, p);

        rectF.bottom = rectF.top + w / 2;
        rectF.left = w / 2;
        rectF.right = w - 15;
        p.setColor(Color.RED);
        canvas.drawArc(rectF, 270, 120, true, p);

        p.setStyle(Paint.Style.STROKE);
        rectF.top = w / 2 + 15;
        rectF.bottom = rectF.top + 300;
        rectF.left = 0;
        rectF.right = w / 2;
        canvas.drawArc(rectF, 0, 100, true, p);

        rectF.bottom = rectF.top + w / 2;
        rectF.left = w / 2;
        rectF.right = w - 15;
        p.setColor(Color.RED);
        canvas.drawArc(rectF, 270, 120, false, p);

        p.setStyle(Paint.Style.FILL_AND_STROKE);
        rectF.top = w + 100;
        rectF.bottom = rectF.top + 300;
        rectF.left = 0;
        rectF.right = w / 2;
        canvas.drawArc(rectF, 0, 270, false, p);

        rectF.bottom = rectF.top + w / 2;
        rectF.left = w / 2;
        rectF.right = w - 15;
        p.setColor(Color.RED);
        canvas.drawArc(rectF, 0, 90, false, p);

    }

}
